<#import "/layout/mainLayout.html" as mainLayout />

<#macro mainheading>

</#macro>
<#assign mainheading = mainheading in mainLayout />

<#macro maincontent>
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <div class="row">

                            <div class="col-sm-1 pull-right">
                                <a class="btn btn-block btn-default "  href="/page/banner/add">添加
                                </a>
                            </div>

                            <!--<div class="col-sm-1 pull-right">-->
                                <!--<button class="btn btn-block btn-default " id ="btn_search" onclick="searchList()">查询-->
                                <!--</button>-->
                            <!--</div>-->
                        </div><!-- /.box-header -->
                    </div>

                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <thead>
                            <tr>
                                <th>图像</th>
                                <th>标题</th>
                                <th>链接</th>

                                <th>时间</th>
                                <th style="text-align: center">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodycontent">


                            </tbody>
                        </table>
                    </div><!-- /.box-body -->
                    <div id="pagecontent" class="pagination"></div>
                </div><!-- /.box -->
            </div>
        </div>
    </section>
</#macro>
<#assign maincontent = maincontent in mainLayout />

<#macro mainfooter>
    <!--layoutmain footer...-->
    <!--<br />-->
    <script src="/js/jquery/jquery.form.js"></script>

    <script type="text/javascript">

        function searchList() {



            LoadList();
        }
        //加载列表
        searchList();
        function LoadList() {
            $('#pagecontent').html('');
            $.ajax({
                    url: '/api/banner/getalllist',
                    dataType: 'json',
                    success: function (data) {
                        if (mortise_layout.ValidataResult(data)) {
                            if (data.result) {

                                var html = '';
                                $.each(data.result, function (index, item) {
                                    html += getHtml(item);
                                })
                                $('#bodycontent').html(html);

                            }
                            else {
                                alert('返回数据错误！');
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
        function  getHtml(dataObject) {

            return ' <tr>'+
                '<td><img src="'+dataObject.fPhoto+'"></td>'+
                '<td>'+dataObject.fTitle+'</td>'+
                '<td>'+dataObject.fUrl+'</td>'+

                '<td>'+dataObject.fIntime+'</td>'+
                '<td>' +
                '<a style="cursor: pointer"   href="/page/banner/update?fid='+dataObject.fId+'">修改</a>&nbsp;&nbsp;' +

                '<a style="cursor: pointer" href="#" onclick="UpdateTop(\''+dataObject.fId+'\')">置顶</a>' +
                '<a style="cursor: pointer" href="#" onclick="DeleteSubject(\''+dataObject.fId+'\')">删除</a></td>'+
                '</tr>';
        }
        
        function DeleteSubject(id) {
            $.ajax({
                    url: '/api/banner/delbanner',
                    data: {'id': id},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }


        function UpdateTop(id) {
            $.ajax({
                    url: '/api/banner/top',
                     data: {'id': id},
                    type: 'POST',
                    contentType: "application/x-www-form-urlencoded",
                    dataType: 'json',
                    success: function (data) {
                        if (data) {
                            if (data.code=='OperateOk'){
                                dialog({
                                    title:'提示',
                                    content: '操作成功！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                                LoadList();
                            }
                            else{
                                dialog({
                                    title:'提示',
                                    content: '操作失败！',
                                    cancel: false,
                                    ok: function () {}
                                }).width(320).showModal();
                            }
                        }
                        else {
                            alert('请求数据失败！');
                        }
                    }
                }
            );
        }
    </script>
</#macro>
<#assign mainfooter = mainfooter in mainLayout />
<@mainLayout.page title="用户管理"/>